﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OBS;
using OBS.Model;

namespace FreeAccessNetdisk.src.classes
{
    public class Uploader : IOperator
    {
        private readonly CloudClient _cloudClient;

        private string _targetDir;

        public Uploader(CloudClient cloudClient, string targetDir)
        {
            _cloudClient = cloudClient;
            _targetDir = targetDir;
        }

        public void CreateFile(ChangeFileInfo changeFile)//upload the file to the cloud
        {
            string localFileDir = Path.Combine(_targetDir, changeFile.FileDir);
            _cloudClient.PutObject(changeFile.FileDir, localFileDir);
        }

        public void DeleteFile(ChangeFileInfo changeFile)// delete the file from the cloud
        {
            _cloudClient.DeleteObject(changeFile.FileDir);
        }

        public void ChangeFile(ChangeFileInfo changeFile)//upload the file to the cloud to replace the old one
        {
            string localFileDir = Path.Combine(_targetDir, changeFile.FileDir);
            _cloudClient.PutObject(changeFile.FileDir, localFileDir);
        }

        public void SetTargetDir(string targetDir)
        {
            this._targetDir = targetDir;
        }
    }

}
